import cv2
import os
import numpy as np
import math
import csv
 
list0=[]
file_dir='//home//mars//Documents//Subject2018//data//VOT2018//ants1//img//'
# file_dir='C:\\Users\\DZF\\Desktop\\flamingo1\\'
for files in os.walk(file_dir):  
    list0.append(files)
img_list=[]
for ii in list0[0][2]:
        img_list.append(ii)
list_img_name=np.array(img_list)
list_img_name.sort() 
# print(list_img_name)
csv_file = csv.reader(open('//home//mars//Documents//Subject2018//ants.csv'))
# csv_file = csv.reader(open('C:\\Users\\DZF\\Desktop\\flamingo1\\groundtruth.csv'))
list2=[]
for i in csv_file:
        list2.append(i)
list3=np.array(list2)
list4=[]
list_temp=[]
for j in list3:
        list_temp=np.array([0.0 if y=='' else float(y) for y in j]) 
        list4.append(list_temp)
list5=np.array(list4)
list_temp1=[]
list_temp2=[]
for k in list5:
        list_temp1=np.array([int(z) for z in k]) 
        list_temp2.append(list_temp1)
list_rect=np.array(list_temp2)
 
 
 
for num in range(0,324):
        #print(list_rect[num][0])
        if list_rect[num][0]>2:
                img_file_name = '/home/mars/Documents/Subject2018/data/VOT2018/ants1/img/'+str(list_img_name[num])
                # img_file_name = 'C:\\Users\\DZF\\Desktop\\flamingo1\\' + str(list_img_name[num])
                # print(img_file_name)
                src=cv2.imread(img_file_name)
                # cv2.imshow('aa',src)
                # cv2.waitKey(0)
                x=list_rect[num][0]
                y=list_rect[num][1]
                w=list_rect[num][2]
                h=list_rect[num][3]
                cv2.rectangle(src,(x,y),(x+w,y+h),(0,0,255),)
                # cv2.imshow('aa',src)
                # cv2.waitKey(0)

                save_file_name="//home//mars//Documents//Subject2018//temp//"+str(list_img_name[num])
                # save_file_name = "C:\\Users\\DZF\\Desktop\\flamingo1\\result\\" + str(list_img_name[num])
                print(save_file_name)
                cv2.imwrite(save_file_name,src)
                
                
                

'''
#test:
data=[]
for line2 in open(path):
    data.append(line2)
 
    #print(line2)
data1=[]
for i in data:
    data1.append(i[:len(i)-1])
data2=[]
data3=[]
for j in data1:
    data2.append(j.split(','))
# print(data2[1])
data4=[]
for k in data2:
    data3=np.array([0.0 if y=='' else float(y) for y in k])
    data4.append(data3)
data_rect=np.array(data4)
'''













